package me.healthcare.common;

import me.healthcare.app.R;
import me.healthcare.model.Message;
import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.TextView;

public class PatientAdapter extends ArrayAdapter<Message> {

	Context context;
	int layoutResourceId;
	Message data[] = null;

	public PatientAdapter(Context context, int layoutResourceId, Message[] data) {
		super(context, layoutResourceId, data);
		this.layoutResourceId = layoutResourceId;
		this.context = context;
		this.data = data;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		View row = convertView;
		ProductHolder holder = null;

		if (row == null) {
			LayoutInflater inflater = ((Activity) context).getLayoutInflater();
			row = inflater.inflate(layoutResourceId, parent, false);

			holder = new ProductHolder();
			holder.patient_name = (TextView) row
					.findViewById(R.id.patient_name);
			holder.message_content = (TextView) row.findViewById(R.id.message);
			holder.detail = (TextView) row.findViewById(R.id.detail_bt);

			row.setTag(holder);
		} else {
			holder = (ProductHolder) row.getTag();
		}

		Message message = data[position];
		holder.patient_name.setText(message.patient_name);
		holder.message_content.setText(message.message_content + ": "
				+ message.time);
		holder.detail.setText(R.string.detail_button);

		return row;
	}

	static class ProductHolder {
		TextView patient_name;
		TextView message_content;
		TextView detail;
	}
}